package cn.hucode.springcloud.person.controller;

import cn.hucode.springcloud.person.dao.PersonRepository;
import cn.hucode.springcloud.person.model.Person;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author hujj
 * @Date 2016/12/9
 */
@RestController
public class PersonController {

    @Autowired
    PersonRepository personRepository;

//    @RequestMapping(method = RequestMethod.POST, value = "/save")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public List<Person> save(@RequestBody String personName) {
        Person p = new Person(personName);
        personRepository.save(p);

        List<Person> personList = personRepository.findAll(new PageRequest(0, 10)).getContent();
        return personList;
    }
}
